<?php
include(APP_PATH.'/Lib/Action/GlobalAction.class.php');

class NewsAction extends GlobalAction {
    public function index(){
        $tblNews = M('blog');
        
        $ret = $tblNews->field('id, title, createtime')->where("type=0 AND lang='{$this->lang}' AND sort>=0")->order('sort DESC, id DESC')->select();
        
        foreach ($ret as $key => $value) {
            $ret[$key]['url'] = U('News/view', "id={$value['id']}");
        }
        
        $this->assign('articles', $ret);
        
        $this->assign('currentPage', 'news');
		$this->display();
    }
    
    public function view() {
        $id = intval($_GET['id']);
        if ($id > 0) {
            $tblNews = M('blog');
        
            $ret = $tblNews->field('title, content')->where("id={$id}")->find();
            $this->assign('article', $ret);
        
            $this->assign('currentPage', 'news');
            $this->display();
        }
    }
}